package cn.jhc.transport;

import android.app.Application;
import android.test.ApplicationTestCase;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import cn.jhc.transport.bean.Environment;
import cn.jhc.transport.service.TransportService;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {

    public ApplicationTest() {
        super(Application.class);
    }

    public void testPost() throws IOException, JSONException {
        JSONObject obj = TransportService.post("http://10.2.51.151:8080/transportservice/type/jason/action/GetCarSpeed.do","{\"CarId\":1}");
        assertNotNull(obj);
//        assertEquals("{\\\"CarSpeed\\\":20}", obj.toString());
    }

    public void testGetCarSpeed() throws IOException, JSONException {
        int speed = TransportService.getCarSpeed(1);
        assertEquals(20,speed);
    }

    public void testGetAllSense() throws IOException, JSONException {
        Environment env = TransportService.getAllSense();
        assertNotNull(env);
        assertTrue(env.getCo2() > 0);
        assertTrue(env.getHumidity() > 0);
        assertTrue(env.getLightIntensity() > 0);
        assertTrue(env.getPm25() > 0);
        assertTrue(env.getTemp() > 0);
    }
}